import React from 'react';
import { plusAction,minusAction } from './redux/actions'
import { connect } from 'react-redux';

class Counter extends React.Component{
    constructor(props) {
        super(props);

    }

    render() {
        return (
            <div>
                <button onClick={() => {
                    this.props.plus();
                }}
                >+</button>
                <div>{this.props.num}</div>
                <button onClick={() => {
                    this.props.minus()
                }}>-</button>
            </div>
        )
    }
}

//将提交action的方法放到props
function mapActionToProps (dispatch) {
    return {
        plus:() => {dispatch(plusAction())},
        minus:() => {dispatch(minusAction())}
    }
}

function mapStateToProps(rootReducer) {
    return {
        num:rootReducer.Reducer.num
    }
}

export default connect(mapStateToProps,mapActionToProps)(Counter);